import React from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'

import { diskRoutes } from './routes/router'
import { isLogined } from './utils/utils'
import Frame from './components/frame/frame'


function App() {
    return (isLogined() ?
        (<Frame>
            <Switch>
                {
                    diskRoutes.map(route => {
                        return route.children.length === 0 ? (<Route key={route.path} path={route.path} exact={true} render={routeProps => {
                            return <route.component  {...routeProps} />
                        }} />) :
                            (route.children.map(v => {
                                return (<Route key={v.path} path={v.path} exact={true} render={routeProps1 => {
                                    return <v.component  {...routeProps1} />
                                }} />)
                            }))
                    })
                })
                }
                <Redirect path="/" to="/disk" />
                <Redirect to="/404" />
            </Switch>
        </Frame>) : (<Redirect to="/login" />)
    )
}

export default App

